package com.ruoyi.app.service.impl;

import com.ruoyi.app.domain.AppUser;
import com.ruoyi.app.domain.AppUserVo;
import com.ruoyi.app.mapper.AppUserMapper;
import com.ruoyi.app.service.PromotionService;
import com.ruoyi.app.utils.PhotoUtils;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: PromotionServiceImpl
 * @Author: chenJie
 * @Description:
 */
@Service
public class PromotionServiceImpl implements PromotionService {

    @Autowired
    private AppUserMapper appUserMapper;

    @Override
    public AjaxResult getPromotion(Integer userId) {
        AppUser appUser = appUserMapper.selectAppUserById(Long.valueOf(userId));
        if (appUser == null) {
            return AjaxResult.error("当前用户不存在");
        }
        AppUserVo appUserVo = new AppUserVo();
        appUserVo.setUserName(appUser.getNickName());
        appUserVo.setInvitationCode(appUser.getInvitationCode());

        // 二维码
        String s = PhotoUtils.generateQRCodeBase64();
        appUserVo.setPhotoCode(s);
        return AjaxResult.success(appUserVo);
    }
}
